/*
 * Author: vdaras
 */

#ifndef GLOBAL_SCRIPT_FUNCTIONS_H
#define	GLOBAL_SCRIPT_FUNCTIONS_H

#include "physics/CollisionEvents.h"
#include "Entity.h"
#include "PhysicsLogic.h"
#include "ResourceManager.h"
#include <string>

class Camera;

using namespace EntitySystem;

/**
 * This routine is used by scripts in order to spawn permanet entities in the
 * game. If we just instansiated an Entity object in script it would be killed
 * when all it's references went out of scope.
 *
 * @param type - type of the entity
 * @param x - spawn x coordinate
 * @param y - spawn y coordinate
 * @param layer - rendering layer to be spawned on.
 */

Entity *SpawnEntity(const std::string &entityType, const std::string &id, int x, int y, const std::string& layer);


/**
 * Returns an Entity by ID. If it does not exist, return NULL.
 *
 * @param ID: id of the entity.
 * @return a handle to the requested Entity or NULL if it doesn't exist.
 */

Entity *FindEntity(const std::string& ID);



/**
 * This function is used by scripts in order to create a aparticle effect.
 * @param type - The type of the effect to spanw.
 * @param position - The position of this effect.
 * @param oneTime - If true the effect will play only once.
 * @param layer - rendering layer to spawn particles on
 * @return  the id of the emiter that was created for this effect. Usefull if oneTime is set to false.
 */

int SpawnParticles(const std::string& type, const Math::Vector2F& position, const Math::Vector2F& direction, bool oneTime, const std::string& layer);

/**
 * Creates an one time audio source to play the specified sound.
 * @param name
 * @param position
 */
void PlaySound(const std::string& name/*, const Math::Vector2F position*/);

/**
 * Plays the specified music file in loop.
 * @param name
 */
void PlayMusic(const std::string& name);

/**
 * Returns the requested entity. NULL if not found.
 * @param name
 * @return 
 */
Entity *FindEntity(const std::string& name);

/**
 * Returns a handle to the current camera service.
 * 
 * @return a pointer to a camera.
 */

Camera *GetCamera( );


/**
 * Loads a key mapping from the xml file keymap.xml.
 *
 * @param tag: the xml node in keympap.xml that contains the mapping.
 */


void LoadKeyAssociations(const std::string& tag);


/**
 * Pushes a script state to the state stack.
 *
 * @param scriptStateClass: name of the angelscript ScriptState class.
 */

void PushState(const std::string& scriptStateClass);


/**
 * Pops the state stack.
 */

void PopStateStack();


/**
 * Proxy method used to extract entity contact info from a physical logic object.
 * Used in order to surpass the triangle of independence between Entity PhysicsLogic and EntityContactInfo
 * @param logic
 * @return 
 */

physicsSystem::PhysicsInternals::EntityContactInfo* GetNextContact(PhysicsLogic* logic);

/**
 * Prints a string to the standard output.
 *
 * @param toPrint - string to print
 */

void Print(const std::string &toPrint);


/**
 * Prints an integer to the standard output.
 *
 * @param toPrint - integer to print
 */

void PrintInt(int toPrint);

/**
 * Prints a bool to the standard output.
 *
 * @param toPrint - bool to print
 */

void PrintBool(bool toPrint);


/**
 * Prints an unsigned integer to the standard output.
 *
 * @param toPrint - unsigned to print
 */

void PrintUnsigned(Uint32 toPrint);


/**
 * Prints a float or a double.
 *
 * @param toPrint - number to print
 */

void PrintReal(double toPrint);

/**
 * Prints a vector.
 *
 * @param toPrint - vector to print
 */

void PrintVector(const Math::Vector2F& toPrint);


/**
 * Returns a pointer to the resource manager.
 */

ResourceManager *GetResourceManager();

#endif	/* GLOBAL_SCRIPT_FUNCTIONS_H */

